{% load i18n %}
{% load comments %}
{% load markup %}
{% load avatar %}

{% get_comment_list for object as comment_list %}
{% if comment_list or object.allow_comments %}
<div id="comments">
    <h3>{% trans "Comments" %}</h3>
    {% if comment_list %}
    <ul>
        {% for comment in comment_list %}
        <li{% if forloop.counter|divisibleby:"2" %} class="altrow"{% endif %}>
            <div class="meta">
                {% with comment.user_name as user_name %}
                {% with comment.user.get_absolute_url as user_link %}
                {% with comment.submit_date as submit_date %}
                {% avatar comment.user %}
                <p>{% blocktrans %}Posted on {{ submit_date }}{% endblocktrans %}{% if comment.user %}{% blocktrans %} by <a href="{{ user_link }}">{{ user_name }}</a>{% endblocktrans %}{% endif %}</p>
                {% endwith %}
                {% endwith %}
                {% endwith %}
                <ul class="actions">
                    {% if comment.pk in obj_perms.comments.delete_comment %}
                    <li class="delete"><a title="{% trans 'Delete' %}" href="{% url comment_delete comment.pk %}">{% trans "Delete" %}</a></li>
                    {% endif %}
                </ul>
            </div>
            <div class="body">{{ comment.comment|markdown }}</div>
        </li>
        {% endfor %}
    </ul>
    {% get_comment_count for object as comment_count %}
    <p class="comment-counter">{% blocktrans %}<strong>{{ comment_count }}</strong> comment(s){% endblocktrans %}</p>
    {% else %}
    <p class="disabled">{% trans "No comments." %}</p>
    {% endif %}
    {% if object.allow_comments and user.is_authenticated %}
    <h3>{% trans "Add comment" %}</h3>
    {% get_comment_form for object as form %}
    <form action="{% comment_form_target %}" method="post">
        {% csrf_token %}
        <input type="hidden" name="next" value="{{ object.get_absolute_url }}" />
        {% for field in form.hidden_fields %}
        {{ field }}
        {% endfor %}
        <p>
            {{ form.comment }}
            {% blocktrans %}Use <a href="http://daringfireball.net/projects/markdown/syntax">MarkDown syntax</a>.{% endblocktrans %}
        </p>
        <span class="submit"><input type="submit" name="post" value="{% trans 'Post' %}"></span>
    </form>
    {% endif %}
</div>
{% endif %}
